package com.ifcar.app.util;

import android.app.Activity;
import android.os.Build;
import android.view.MotionEvent;

/**
 * 版本兼容工具类<br/>
 * 类名命名规则：<br/>
 * XxxCompat为接口<br/>
 * XxxCompat_DONUT_DOWN类表示DONUT以下(包括DONUT)版本适用<br/>
 * XxxCompat_DONUT_UP类表示DONUT以上版本适用<br/>
 * 
 * @author wjying
 */
public class VersionCompat {

	/**
	 * Activity
	 */
	private final static ActivityCompat ACTIVITY_COMPAT;

	static {
		if (Build.VERSION.SDK_INT > Build.VERSION_CODES.DONUT) {
			ACTIVITY_COMPAT = new ActivityCompat_DONUT_UP();
		} else {
			ACTIVITY_COMPAT = new ActivityCompat_DONUT_DOWN();
		}
	}

	private static class ActivityCompat_DONUT_UP implements ActivityCompat {
		@Override
		public void overridePendingTransition(Activity activity, int enterAnim,
				int exitAnim) {
			activity.overridePendingTransition(enterAnim, exitAnim);
		}
	}

	private static class ActivityCompat_DONUT_DOWN implements ActivityCompat {
		@Override
		public void overridePendingTransition(Activity activity, int enterAnim,
				int exitAnim) {
		}
	}

	public interface ActivityCompat {
		public void overridePendingTransition(Activity activity, int enterAnim,
				int exitAnim);
	}

	public static ActivityCompat getActivityCompat() {
		return ACTIVITY_COMPAT;
	}

	/**
	 * MotionEvent
	 */

	private static MotionEventCompat MOTION_EVENT_COMPAT;

	static {
		if (Build.VERSION.SDK_INT > Build.VERSION_CODES.DONUT) {
			MOTION_EVENT_COMPAT = new MotionEventCompat_DONUT_UP();
		} else {
			MOTION_EVENT_COMPAT = new MotionEventCompat_DUNUT_DOWN();
		}
	}

	private static class MotionEventCompat_DONUT_UP implements
			MotionEventCompat {
		@Override
		public float getPointerCount(MotionEvent event) {
			return event.getPointerCount();
		}
	}

	private static class MotionEventCompat_DUNUT_DOWN implements
			MotionEventCompat {
		@Override
		public float getPointerCount(MotionEvent event) {
			return 1;
		}
	}

	public interface MotionEventCompat {
		public float getPointerCount(MotionEvent event);
	}

	public static MotionEventCompat getMotionEventCompat() {
		return MOTION_EVENT_COMPAT;
	}
}
